
from collections import deque
n = 9
r = [0] * n
c = [0] * n
b = [0] * n

nums = []
nums.append("080010000")
nums.append("0001004007")
nums.append("507306000")
nums.append("000080041")
nums.append("023000790")
nums.append("710090500")
nums.append("000105208")
nums.append("300200000")
nums.append("000070050")

array = [[0] * n for _ in range(n)]

for i in range(n):
    for j in range(n):
        array[i][j] = ord(nums[i][j]) - ord('0')

cnts = [0] * (n + 1)
for i in range(n):
    for j in range(n):
        m = array[i][j]
        if m != 0:
            p = 1 << m
            r[i] |= p
            c[j] |= p
            b[i // 3 * 3 + j // 3] |= p
            cnts[m] += 1


queue = deque()
for i in range(1, n + 1):
    if cnts[i] < 9:
        queue.append((i, cnts[i]))
s = set()
while queue:
    a, cnt = queue[0]
    p = 1 << a
    for i in range(n):
        if b[i] & p == 0:
            pr = pc = -1
            for ri in range(i // 3 * 3, (i // 3 + 1) * 3):
                if pr == -2:
                    break
                for ci in range(i % 3 * 3, i % 3 * 3 + 3):
                    if array[ri][ci] == 0 and r[ri] & p == 0 and c[ci] & p == 0:
                        if pr == -1:
                            pr, pc = ri, ci
                        else:
                            pr = -2
                            break
            if pr != -1 and pr != -2:
                array[pr][pc] = a
                cnt += 1
                r[pr] |= p
                c[pc] |= p
                b[i] |= p
    if cnt < 9:
        queue.append((a, cnt))

for row in array:
    print(row)

# for i in range(10):
#     print(h[i])